{"componentChunkName":"component---src-templates-post-tsx","path":"/prototype/","result":{"data":{"markdownRemark":{"html":"<h1 id=\"프로토-타입이란\" style=\"position:relative;\"><a href=\"#%ED%94%84%EB%A1%9C%ED%86%A0-%ED%83%80%EC%9E%85%EC%9D%B4%EB%9E%80\" aria-label=\"프로토 타입이란 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>프로토 타입이란?</h1>\n<hr>\n<blockquote>\n<p>Prototype이란, <strong><em>'원형'</em></strong> 의 뜻을 가지며, 시스템의 미완성 버전 또는 중요한 가능들이 포함된 시스템의 초기모델을 의미한다.</p>\n</blockquote>\n<p>  JS에서는 모든 것이 객체입니다. 우리가 사용하는 배열이나 함수도 하나의 객체인데요. 우리가 정의하지 않았던 JS의 내장 함수들, 배열의 <code class=\"language-text\">forEach()</code>, <code class=\"language-text\">includes()</code>와 함수의 <code class=\"language-text\">bind()</code>와 같은 함수들은 우리가 정의하지 않아도 객체에 상속되어 사용할 수 있습니다. 이를 위해 JS는 Prototype, 즉 <strong>'객체의 원형'</strong> 을 정의하는 방식을 통해 객체가 가지는 특성이나 메소드의 상속을 구현합니다. Prototype을 이해하기 위해서는 반드시 <strong>'객체의 원형'</strong> 이라는 의미를 기억하는 것이 중요합니다. 이번 포스트에서는 JS가 Prototype을 통해 어떻게 상속을 구현할 수 있는지를 알아보고자 합니다. 본론으로 들어가기 전에 알아야 할 것이 하나 있습니다.</p>\n<h3 id=\"생성자-함수와-code-classlanguage-textnewcode-연산자를-통한-객체-생성과정\" style=\"position:relative;\"><a href=\"#%EC%83%9D%EC%84%B1%EC%9E%90-%ED%95%A8%EC%88%98%EC%99%80-code-classlanguage-textnewcode-%EC%97%B0%EC%82%B0%EC%9E%90%EB%A5%BC-%ED%86%B5%ED%95%9C-%EA%B0%9D%EC%B2%B4-%EC%83%9D%EC%84%B1%EA%B3%BC%EC%A0%95\" aria-label=\"생성자 함수와 code classlanguage textnewcode 연산자를 통한 객체 생성과정 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>생성자 함수와 <code class=\"language-text\">new</code> 연산자를 통한 객체 생성과정</h3>\n<p>  객체의 상속을 구현하기 전에 우리는 객체의 생성방법에 대해서 이해해야 합니다. 객체 생성과정에서 Prototype을 사용하기 때문입니다. 생성자 함수는 함수 내에서 <code class=\"language-text\">this</code>를 통해서 새롭게 생성할 객체의 형식을 정의하는 함수입니다. 생성자 함수로 객체의 형식을 정의했다면 <code class=\"language-text\">new</code> 연산자를 통해서 새로운 객체를 생성합니다.<span class='small-text'>(여기서 생성자 함수는 일반적인 함수와 다를 것이 없지만, 클래스와 같이 함수명의 첫 글자를 대문자로 사용하는 관례가 존재합니다.)</span> 객체 생성과정을 좀 더 세분화하면 아래의 순서를 가집니다.</p>\n<ol>\n<li>\n<p><strong>새로운 객체를 생성하고 생성된 객체가 생성자 함수의 <em>Prototype Object</em>를 참조할 수 있도록 합니다.</strong></p>\n<blockquote>\n<p>구체적으로 표현하자면, 생성자 함수가 가지는 <em>Prototype Object</em>를 <em>Prototype Link</em>에 바인딩 된 새로운 객체를 생성합니다.</p>\n</blockquote>\n</li>\n<li><strong>생성된 객체를 함수 내의 <code class=\"language-text\">this</code>로 바인딩하여 함수를 수행합니다. 이때, <code class=\"language-text\">this</code>를 통해 명시적으로 호출되는 프로퍼티와 메소드를 객체에 추가합니다.</strong><br>\n<br/></li>\n<li><strong>함수의 수행이 완료되면 해당 객체를 반환합니다.</strong>  </li>\n</ol>\n<p>  여기서 우리가 집중할 것은 첫 번째 과정입니다. Prototype이라는 단어가 가지는 '<strong>원형</strong>'이라는 의미에서처럼 JS는 객체에 필요한 프로퍼티와 메소드를 전달하기 위해 Prototype을 바인딩하는 작업이 가장 먼저 수행되고 있습니다. 그럼 이제 Prototype을 구성하는 두 개념 <em>Prototype Object</em>와 <em>Prototype Link</em>에 대해 알아보도록 하겠습니다. <span class='small-text'>(두 번째 과정의 <code class=\"language-text\">this</code>는 다음 포스팅에서 설명하도록 하겠습니다.)</span></p>\n<br/>\n<h1 id=\"프로토타입의-구조\" style=\"position:relative;\"><a href=\"#%ED%94%84%EB%A1%9C%ED%86%A0%ED%83%80%EC%9E%85%EC%9D%98-%EA%B5%AC%EC%A1%B0\" aria-label=\"프로토타입의 구조 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>프로토타입의 구조</h1>\n<p>  Prototype은 객체 자기 자신의 원형을 가리키는 <strong><em>Prototype Link</em></strong>, 자신을 통해 생성될 객체의 원형을 의미하는 <strong><em>Prototype Object</em></strong>로 구성되어있습니다. 이 두 가지 개념을 하나씩 살펴보겠습니다.</p>\n<h2 id=\"prototype-object\" style=\"position:relative;\"><a href=\"#prototype-object\" aria-label=\"prototype object permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prototype Object</h2>\n<hr>\n<blockquote>\n<p><strong>함수가 가지는 프로퍼티로, 자신(함수)을 통해 생성되는 객체들의 원형 객체를 말한다.</strong> <em>(자신의 원형이 아님, 이후에 생성될 객체들의 원형인 것을 주의하자!)</em></p>\n</blockquote>\n<p>  중요한 것은 이 객체가 <strong>'함수가 가지는 프로퍼티'</strong>라는 것입니다. <em>Prototype Object</em>는 생성자 함수를 통해 생성될 객체의 원형을 의미합니다. 객체를 생성할 수 있는 함수에서 사용되는 객체임을 기억해야 합니다. 위에서 생성자 함수를 통한 객체 생성 과정을 설명하였습니다. 그 과정에서 <em>Prototype Object</em>는 함수가 선언되는 시점에 함수와 함께 생성되고, 생성된 <em>Prototype Object</em>는 함수의 <code class=\"language-text\">prototype</code> 프로퍼티에 바인딩 됩니다.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Human</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t\t<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>  위의 예제에서 이름 프로퍼티와 인스턴스의 이름을 출력하는 메소드를 가지는 객체의 생성자 함수 <code class=\"language-text\">Human</code>을 선언하였습니다. JS는 생성자 함수 <code class=\"language-text\">Human</code>를 선언하는 시점에 자신의 <em>Prototype Object</em>를 생성하고 <code class=\"language-text\">prototype</code>프로퍼티에 바인딩합니다. 아래는 결과를 그림으로 표현한 것입니다.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 189px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/77050fc5aa3cf2d525e9624e7dbb4622/0f8c7/prototype_1.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 170.27027027027026%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAiCAYAAABfqvm9AAAACXBIWXMAAAsSAAALEgHS3X78AAADUklEQVRIx62W2UpjQRCGz/s/gCB4obkQIYIiKqhxuXCJMXHfNe4ad5O4r798xZTTSU5iBqah6NOnuv9au6oj/RlfX18239zcaG1tTfv7+zo4ONDJyYnR0NCQ2tvb1dvbq7a2Ns3Nzens7ExHR0fa29uzeXp6WpED+Xx1daXn52f7/vj4sPXj46MODw+1sLCgzc1NZTIZbW9v275yuew66eLiQpGDOWCxWNTu7q5ub2+1uLioZDKpzs5OdXR0qKurS93d3ZqamjJtW1palEgktLW1ZftzuVylhkjETEzh++npSW9vb7q8vNTx8bG5AU1PT09tH//Zc39/r9fXVwOOQt+dn59rZ2dHpVJJ4cDUsbExDQwMaHR0VCMjI+rv77e94UCRH8BCoWA+QxoaIBn/QPx3t0Cfn582+34UwKKNjY2/gGj38vJivri+vrYD7+/vZsrs7KwFYmlpScvLy1pdXdX6+rr5mDPsY+CSGsC7uzsz3zVA04mJCa2srCiVSmlyctJSh2/MR7NfAYkyKYBPcAWpgxAyAAuc+A+ffXxXRDk0Gb/EDYQh6OHhIZaP72M1JB0wg7UT6eOZgFDWzsNsAoVlFYDcCNaYgTRMYfZvrmBra6tds5DnfHL1B7CRKeHI5/MN+RGquoYOyL84cj95HsZR5MjkHv74bThgWFAqNCRxSQeqCD4gKIDXI0yurlAVgEgkakQIx3LVAEVINfGfwFVXqBpALw5o28yIA6oA5IoRZTTgG+B6BP9XDUlSKMyrOCIPqdQNAfFbM9H1AWjDKIeA9XIr1OafAesFwXlcu/+ioYNQphrta0rDcFBYPRdj06Y6KIBSeT2yXlyZuQA0K87wz29PmAk1gNRBWiTApBIdb35+3vpKNps1YVRmegtr+OwjPzlbF9ATmcM8MXh6zMzMWIMCKJ1O2xpeWIhrAJFEQ6KcwfPeQRXHd9x1yhzNy3sLBdkpVkPAwoHf6HDj4+PW8Wj0w8PDtq6+FAYYFgU32XsymvBCQDOcTh7yOuPFRWOnoeFDd1FE5vtrywMBgJvHAfhhGYMHoR1838cc8YzgAQQwGhBFCm042EyzHxwctHdiT0+P+vr6at5AZnLcNaN6e1djRiBaIwxTMZk1SlR3v2/KWRXDotSl7AAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"prototype 1\"\n        title=\"prototype 1\"\n        src=\"/static/77050fc5aa3cf2d525e9624e7dbb4622/0f8c7/prototype_1.png\"\n        srcset=\"/static/77050fc5aa3cf2d525e9624e7dbb4622/12f09/prototype_1.png 148w,\n/static/77050fc5aa3cf2d525e9624e7dbb4622/0f8c7/prototype_1.png 189w\"\n        sizes=\"(max-width: 189px) 100vw, 189px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<h4 id=\"1-아래-박스는-생성자-함수-code-classlanguage-texthumancode입니다-생성자-함수는-기본적으로-두-개의-프로퍼티를-가집니다\" style=\"position:relative;\"><a href=\"#1-%EC%95%84%EB%9E%98-%EB%B0%95%EC%8A%A4%EB%8A%94-%EC%83%9D%EC%84%B1%EC%9E%90-%ED%95%A8%EC%88%98-code-classlanguage-texthumancode%EC%9E%85%EB%8B%88%EB%8B%A4-%EC%83%9D%EC%84%B1%EC%9E%90-%ED%95%A8%EC%88%98%EB%8A%94-%EA%B8%B0%EB%B3%B8%EC%A0%81%EC%9C%BC%EB%A1%9C-%EB%91%90-%EA%B0%9C%EC%9D%98-%ED%94%84%EB%A1%9C%ED%8D%BC%ED%8B%B0%EB%A5%BC-%EA%B0%80%EC%A7%91%EB%8B%88%EB%8B%A4\" aria-label=\"1 아래 박스는 생성자 함수 code classlanguage texthumancode입니다 생성자 함수는 기본적으로 두 개의 프로퍼티를 가집니다 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. 아래 박스는 생성자 함수 <code class=\"language-text\">Human</code>입니다. 생성자 함수는 기본적으로 두 개의 프로퍼티를 가집니다.</h4>\n<ul>\n<li>\n<p><strong><code class=\"language-text\">prototype</code>  프로퍼티</strong></p>\n<p>   생성자 함수는 자신을 통해 생성될 객체의 원형, <em>Prototype Object</em>를 <code class=\"language-text\">prototype</code> 프로퍼티를 통해 참조하고 있습니다.<br>\n<br/>\n</p>\n</li>\n<li>\n<p><strong><code class=\"language-text\">[[Prototype]]</code> 프로퍼티</strong></p>\n<p>   아래에서 설명할 <code class=\"language-text\">Prototype Link</code>를 의미하므로 추후 설명하도록 하겠습니다.</p>\n</li>\n</ul>\n<br/>\n<br/>\n<h4 id=\"2-위-박스는-생성자-함수-code-classlanguage-texthumancode의-prototype-object입니다\" style=\"position:relative;\"><a href=\"#2-%EC%9C%84-%EB%B0%95%EC%8A%A4%EB%8A%94-%EC%83%9D%EC%84%B1%EC%9E%90-%ED%95%A8%EC%88%98-code-classlanguage-texthumancode%EC%9D%98-prototype-object%EC%9E%85%EB%8B%88%EB%8B%A4\" aria-label=\"2 위 박스는 생성자 함수 code classlanguage texthumancode의 prototype object입니다 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. 위 박스는 생성자 함수 <code class=\"language-text\">Human</code>의 <em>Prototype Object</em>입니다.</h4>\n<p>  객체의 원형이라는 의미는 곧 <code class=\"language-text\">Human</code> 함수를 통해 생성될 객체들이 사용할 수 있는 영역이라고 생각하면 되겠습니다. <strong>모든 함수의 <em>Prototype Object</em>는 기본적으로 그림과 같이 두 개의 프로퍼티와 빈 슬롯<code class=\"language-text\">{}</code>을 가집니다.</strong> 구조를 하나씩 살펴보겠습니다. </p>\n<ul>\n<li>\n<p><strong><code class=\"language-text\">constructor</code> 프로퍼티</strong></p>\n<blockquote>\n<p><strong><em>Prototype Object</em>이 가지는 프로퍼티로, 자신을 사용하는 생성자 함수를 가리킨다.</strong></p>\n</blockquote>\n<p>   해당 프로퍼티를 통해서 객체는 자신의 생성자 함수를 참조할 수 있습니다. 주로 생성자 함수가 가지는 <em>static method</em>를 사용하고자 할 때 사용하거나, 해당 객체와 동일한 생성자 함수를 통한 객체를 만들기 위함입니다.</p>\n</li>\n</ul>\n <br/>\n<ul>\n<li>\n<p><strong><code class=\"language-text\">[[Prototype]]</code> 프로퍼티</strong></p>\n<blockquote>\n<p><strong>모든 객체가 가지는 프로퍼티로, 객체 자신의 원형 객체인 <em>Prototype Object</em>를 가리킵니다.</strong></p>\n</blockquote>\n<p>   가장 헷갈리는 부분 중의 하나가 <em>Prototype Object</em>의 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티입니다. <em>Prototype Object</em>도 하나의 객체이기 때문에 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티를 가집니다. <strong>모든 <em>Prototype Object</em>의 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 동일하게 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>를 가리킵니다.</strong> 즉, <em>Prototype Object</em>는 <code class=\"language-text\">Object</code>를 통해서 만들어진, 말 그대로 객체라는 의미가 됩니다. (모든 객체가 Object의 자손임을 의미합니다.) 그림으로 표현하면 아래와 같습니다.<br>\n<br/> </p>\n<p> <span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/8e307fbd84c6606a681a4a1a552144d6/a1253/prototype_2.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 49.32432432432432%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABQUlEQVQoz32Sy66DMAxE+f9fY8MSVIQELQXxhtLyKODqWDKX1Y0UJXFmxhM7zr7v0nWdJEkirutKEARSVZUQ/2+8Xi+53+/K8X1fOfM8i/N+v6Xve6nrWsIwlCzLFLyuq4pu26bz+/2ee+LwjPN8PvXctu2fIPPxeEjTNHrx+Xw0IxPxcRzPMxMMnDRNpSgKveelzrIsCiAzoGmahJgNxLiHSHKcWpyJAfDsMeGYCAHW4zhOMZLgglp5nidxHOv5ijFD8NUhgmTGMiv1MQJuAFNwmkXNhmE4XwCOvXG5c3Bl47pnIM6TKDq/AGFc8LQrxwyAd3BAEDAkukwmA3GHADFrGByc4Zgy5HmuP4OYCkLARRRF2mlcXP8he5pybRZPLMtSORhBUJti/4fst9tNs1F4GnLtNGRWG9QNnP1DBNH5AW86AfbISwyyAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"prototype 2\"\n        title=\"prototype 2\"\n        src=\"/static/8e307fbd84c6606a681a4a1a552144d6/fcda8/prototype_2.png\"\n        srcset=\"/static/8e307fbd84c6606a681a4a1a552144d6/12f09/prototype_2.png 148w,\n/static/8e307fbd84c6606a681a4a1a552144d6/e4a3f/prototype_2.png 295w,\n/static/8e307fbd84c6606a681a4a1a552144d6/fcda8/prototype_2.png 590w,\n/static/8e307fbd84c6606a681a4a1a552144d6/a1253/prototype_2.png 657w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span>  </p>\n <br/>\n<ul>\n<li>   위 그림에서 생성자 함수 <code class=\"language-text\">Human</code>, <code class=\"language-text\">Animal</code> 모두 <em>Prototype Object</em>를 가지며 <em>Prototype Object</em>들의 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 함수가 다르더라도 동일하게 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>를 가리키고 있습니다.</li>\n</ul>\n<br/>\n<ul>\n<li><code class=\"language-text\">Object</code> <em>Prototype Object</em>의 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 <code class=\"language-text\">null</code> 값을 가집니다. <code class=\"language-text\">[[Prototype]]</code> 프로퍼티가 객체 자신의 원형객체인 <em>Prototype Object</em>를 가리킨다고 설명하였는데 <code class=\"language-text\">Object</code> <em>Prototype Object</em>는 자신의 원형객체가 존재하지 않으므로 <code class=\"language-text\">null</code>이 됩니다.</li>\n</ul>\n</li>\n</ul>\n<br/>\n<ul>\n<li>\n<p><strong><code class=\"language-text\">{}</code></strong></p>\n<blockquote>\n<p><strong>Prototype을 통해 공유될 프로퍼티와 메소드가 들어갈 영역</strong>  </p>\n</blockquote>\n<p>   생성자 함수의 <em>Prototype Object</em>이 가지는 프로퍼티와 메소드가 정의되는 영역입니다. 이후에 설명할 <em>Prototype Link</em>에 의해 모든 객체가 참조할 수 있으며, 생성자 함수의 <code class=\"language-text\">prototype</code> 프로퍼티를 통해서 추가할 수 있습니다. </p>\n<br/>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Human</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n <span class=\"token comment\">// 생성자 함수의 prototype 프로퍼티를 통해서 메소드를 추가하였다.</span>\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">printName</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n</ul>\n<br/>\n<br/>\n<br/>\n<h2 id=\"prototype-link\" style=\"position:relative;\"><a href=\"#prototype-link\" aria-label=\"prototype link permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prototype Link</h2>\n<hr>\n<blockquote>\n<p><strong>모든 객체(함수 포함)가 가지는 프로퍼티로, 자신의 원형 <em>Prototype Object</em>을 참조하기 위해 사용되는 포인터이다.</strong> </p>\n</blockquote>\n<p>  모든 객체는 <em>Prototype Link</em>를 가지며, <code class=\"language-text\">[[Prototype]]</code> 프로퍼티를 통해서 구현됩니다. <strong>이 프로퍼티는 자신의 원형 객체 즉, 객체 자신을 생성할 때 사용하였던 생성자 함수의 <em>Prototype Object</em>를 가리킵니다.</strong> 이 프로퍼티를 통해 객체는 생성자 함수의 <em>Prototype Object</em>가 가진 프로퍼티와 메소드를 사용할 수 있습니다. 생성자 함수 <code class=\"language-text\">Human</code>과 이 함수를 통해 생성되는 인스턴스 <code class=\"language-text\">chanwoo</code> 예제로 설명하도록 하겠습니다.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Human</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// 생성자 함수의 prototype 프로퍼티를 통해서 메소드를 추가하였다.</span>\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">printName</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> chanwoo <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Human</span><span class=\"token punctuation\">(</span><span class=\"token string\">'chanwoo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>  인스턴스 <code class=\"language-text\">chanwoo</code>는 생성자 함수 <code class=\"language-text\">Human</code>을 사용하여 생성되었습니다. <em>Prototype Link</em>의 정의에 따라 <code class=\"language-text\">chanwoo</code>는 객체이기 때문에 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티를 가지고 있습니다. 그림으로 표현하자면 아래와 같습니다. </p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 407px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/b8317d8c873aaf678fbb0795c10de3a7/0ff56/prototype_3.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 113.51351351351352%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAXCAYAAAALHW+jAAAACXBIWXMAAAsSAAALEgHS3X78AAACTElEQVQ4y5WU16oCMRCG9/0fyQsvFBFUbNh7wd57dw7fwCxxkXP2BGLclL/MZOK932+hMS4WC9lutzKdTiWbzUo+n9e5+Xwuy+XS3/db8/i5XC6yXq/14P1+l16vJ6VSSTvgx+NRNptNOMDX6yXn81kej4equ91uMhqNZDgcSq1Wk/F4rOu73S4cIOydTkdOp5Ps93sFAGg2m0mj0ZBms6kErIUCxEq/31cVqIMAcEbrh8NB10Jb5hAbsf18Pv0ebH+BKSCbzK4p4tti9m9A9wNbliDiSOzIOiShLdsGLKKS69NqtSQajUoymdRsE2c3KW4PkviABJ7McrBYLEoqlZJMJiPlcllJvoXABbPRM3XuIaqDq9Rut9UuIUAl+wgB34x8BxX7gICZtUqloirT6bSCMkfFkCyc2FUi3m4YfIUwcmgymfglh8LBYKCWSZDVsjXCAzEkrn0F5C6ycL1etfxQQGJQhXLmqHeaWUUh6xYGu7eaFKyyCCA2OAxosDGPE8ghjEQiGm++IUWYZ4+CKWGkk6TgnbM1ajwWi0k8HpdEIqGlCzBYCmhqGAFFZbfb1TihGlXYwiYqTSHAgHHpcekrBIgPV0G1WtWXhv+QWHY5zDfJsgQyt1qt1NWHQlhgJ6tsLBQKmm0jYh+PMA8wZFwp9kIGGKAe2QGIThxoXBEs1+t1nTe72AcMEIhQDzHlyTuqgHZtOMQEB1lEXS6XU3DYsRksNYspo3XPzST/rZysQebO2Yh9Lv7X18YtHRf825yR8LTxGqHe5lj/AZ7l6TL273vRAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"prototype 3\"\n        title=\"prototype 3\"\n        src=\"/static/b8317d8c873aaf678fbb0795c10de3a7/0ff56/prototype_3.png\"\n        srcset=\"/static/b8317d8c873aaf678fbb0795c10de3a7/12f09/prototype_3.png 148w,\n/static/b8317d8c873aaf678fbb0795c10de3a7/e4a3f/prototype_3.png 295w,\n/static/b8317d8c873aaf678fbb0795c10de3a7/0ff56/prototype_3.png 407w\"\n        sizes=\"(max-width: 407px) 100vw, 407px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<ol>\n<li><code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 <code class=\"language-text\">__proto__</code> 프로퍼티를 통해 접근할 수 있습니다. 하지만 최근에는 <code class=\"language-text\">__proto__</code> 프로퍼티 대신 <code class=\"language-text\">Object.getPrototypeOf()</code>, <code class=\"language-text\">Object</code>의 정적 메소드를 사용하여 접근하도록 권장하고 있습니다.</li>\n</ol>\n<br/>\n<ol start=\"2\">\n<li>인스턴스 <code class=\"language-text\">chanwoo</code>의 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 객체 자신을 생성하기 위해 사용한 생성자 함수인 <code class=\"language-text\">Human</code>의 <em>Prototype Object</em>를 가리키고 있습니다.  </li>\n</ol>\n<br/>\n<ol start=\"3\">\n<li>생성자 함수 <code class=\"language-text\">Human</code>의 <em>Prototype Object</em>의 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>를 가리킵니다. <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>는 모든 <em>Prototype Object</em>의 원형이라는 의미를 가집니다.  </li>\n</ol>\n<br/>\n<ol start=\"4\">\n<li><code class=\"language-text\">Object</code>의 <em>Prototype Object</em>의 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 <code class=\"language-text\">null</code> 값을 가집니다. JS는 모든 것이 객체이며, 모든 객체의 원형이 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>이기 때문입니다. 가장 기본이 되는 원형이기 때문에 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>가 가진 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티가 <code class=\"language-text\">null</code> 값을 가지게 됩니다.</li>\n</ol>\n<br/>\n<h2 id=\"그래서-prototype-object-prototype-link를-말하자면\" style=\"position:relative;\"><a href=\"#%EA%B7%B8%EB%9E%98%EC%84%9C-prototype-object-prototype-link%EB%A5%BC-%EB%A7%90%ED%95%98%EC%9E%90%EB%A9%B4\" aria-label=\"그래서 prototype object prototype link를 말하자면 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>그래서 Prototype Object, Prototype Link를 말하자면..</h2>\n<p>  JS는 Prototype을 통해 객체 지향의 상속을 구현합니다. JS의 객체는 모두 자신의 원형이 존재합니다. 이 원형을 Prototype이라고 하는데요. Prototype은 <em>Prototype Object</em>와 <em>Prototype Link</em>로 구성되어있습니다. </p>\n<ul>\n<li><strong><em>Prototype Object</em>는 함수 측의 구현으로, 생성자 함수를 통해 생성되는 인스턴스들의 원형 객체를 말합니다. 생성자 함수가 선언되는 시점에 해당 함수의 <em>Prototype Object</em>가 생성되며, 함수의 <code class=\"language-text\">prototype</code> 프로퍼티를 통해서 <em>Prototype Object</em> 내에 상속할 프로퍼티와 메소드를 선언할 수 있습니다.</strong> </li>\n</ul>\n<br/>\n<ul>\n<li><strong><em>Prototype Link</em>는 객체 측의 구현으로, 객체 자신이 생성될 때 사용된 원형 객체, <em>Prototype Object</em>를 참조하고 있습니다. <em>Prototype Link</em>는 <code class=\"language-text\">[[Prototype]]</code> 프로퍼티에 저장되며, 모든 객체가 이 프로퍼티를 가지고 있습니다. 생성자 함수로 생성된 인스턴스의 경우, 함수가 가진 <em>Prototype Object</em>가 이 프로퍼티에 바인딩 되며, 이 프로퍼티를 통해 <em>Prototype Object</em>가 가진 프로퍼티와 메소드를 사용할 수 있습니다.</strong></li>\n</ul>\n<br/>\n<ul>\n<li><strong>모든 <em>Prototype Object</em>는 인스턴스들이 참조할 수 있는 프로퍼티와 메소드가 저장될 슬롯과 두 프로퍼티를 가집니다. <code class=\"language-text\">constructor</code> 프로퍼티는 자신(<em>Prototype Object</em>)을 사용하여 인스턴스를 생성할 생성자 함수를 참조합니다. <code class=\"language-text\">[[Prototype]]</code> 프로퍼티는 자신의 원형 객체인 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>를 참조하고 있습니다. 그리고 아래에서 서술할 <em>Prototype Chain</em>에 의해 모든 객체는 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>가 가지는 모든 프로퍼티와 메소드에 접근할 수 있습니다.</strong></li>\n</ul>\n<br/>\n<br/>\n<h1 id=\"prototype-chain\" style=\"position:relative;\"><a href=\"#prototype-chain\" aria-label=\"prototype chain permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prototype Chain</h1>\n<hr>\n<blockquote>\n<p><strong><em>Prototype Object</em>과 <em>Prototype Link</em>로 구성된 Prototype을 통해 상속을 구현하는 방식이다. 포인터를 통해 선형적으로 참조하는 형식이 chain과 같은 모양이기에 <em>Prototype Chain</em>이라고 합니다.</strong></p>\n</blockquote>\n<p>  모든 객체는 자신의 원형 객체 즉, <em>Prototype Object</em>를 참조할 수 있습니다. 이 <em>Prototype Object</em>에는 객체가 상속받을 프로퍼티와 메소드가 저장되어있고, <em>Prototype Link</em>을 통해 <em>Prototype Object</em>에 저장되어있는 프로퍼티와 메소드에 접근할 수 있습니다. Prototype을 통해 상속받는 프로퍼티와 메소드를 사용하는 동작 방식은 아래와 같습니다. </p>\n<ol>\n<li><strong>사용하고자 하는 프로퍼티와 메소드가 객체의 슬롯<code class=\"language-text\">{}</code>에 존재하는지 확인합니다.</strong><br>\n<br/>  </li>\n<li><strong>현재 객체에 존재하지 않는다면, 객체의 <em>Prototype Link</em>를 통해 원형 객체인 <em>Prototype Object</em>에 접근합니다.</strong><br>\n<br/></li>\n<li><strong>사용하고자 하는 프로퍼티와 메소드가 <em>Prototype Object</em>가 가진 슬롯에 존재하는지 확인합니다.</strong><br>\n<br/>  </li>\n<li><strong>현재의 <em>Prototype Object</em>에 존재하지 않는다면, 이 <em>Prototype Object</em>의 객체로 간주하고 1~3번의 과정을 반복합니다.</strong><br>\n<br/></li>\n<li><strong><em>Prototype Object</em>를 접근하는 과정에서 객체의 <em>Prototype Link</em>가 <code class=\"language-text\">null</code>인 경우, 즉 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>인 경우 조회가 종료됩니다.</strong></li>\n</ol>\n<p>  이렇게 Prototype을 통해 객체가 참조할 수 있는 프로퍼티와 메소드를 조회하는 과정에서 여러 개의 <em>Prototype Object</em>를 거친다고해서 <em>Prototype Chain</em>이라고 합니다. 위에서 사용하였던 예제와 예제의 Prototype 구조 그림을 통해 <em>Prototype Chain</em>을 설명해보도록 하겠습니다. </p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Human</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t\t<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// 생성자 함수의 prototype 프로퍼티를 통해서 메소드를 추가하였다.</span>\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">printName</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> chanwoo <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Human</span><span class=\"token punctuation\">(</span><span class=\"token string\">'chanwoo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nchanwoo<span class=\"token punctuation\">.</span><span class=\"token function\">printName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                    <span class=\"token comment\">// ----- A</span>\n\nchanwoo<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// ----- B</span>\n\nchanwoo<span class=\"token punctuation\">.</span><span class=\"token function\">printNickName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// ----- C</span></code></pre></div>\n<p>  인스턴스 <code class=\"language-text\">chanwoo</code>는 생성자 함수가 객체의 형식을 정의하였던대로 <code class=\"language-text\">name</code> 프로퍼티를 가집니다. <code class=\"language-text\">name</code> 프로퍼티는 인스턴스의 슬롯<strong>(1)</strong> 에 존재하고 있습니다. <code class=\"language-text\">name</code> 프로퍼티를 출력하는 메소드인 <code class=\"language-text\">printName()</code>을 모든 인스턴스에 선언하게 되면 동일한 함수임에도 인스턴스마다 선언되게 됩니다. 그래서 우리는 모든 인스턴스가 참조할 수 있는 영역인, 생성자 함수 <code class=\"language-text\">Human</code>의 <em>Prototype Object</em> 내부에 <code class=\"language-text\">printName()</code>을 선언하였습니다<strong>(3)</strong>. 이후 인스턴스 <code class=\"language-text\">chanwoo</code>가 <code class=\"language-text\">printName()</code>을 호출한 상황입니다. 인스턴스가 이 함수를 사용하기 위해 Prototype을 사용하는 과정은 파란색 숫자 순입니다.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 429px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/7c71b35ad16d96a62ba9960d95d6d591/3d026/prototype_4.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 102.02702702702702%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsSAAALEgHS3X78AAACy0lEQVQ4y42UC3OaUBCF/fH5WZ0mtdFpp7VNjMSYCBh8APJ+yEOB090lqO0kTZi5XoG73z17di+9pmmQF4DrFgiCBEVRYvb4hIlyj0eaM3rp+wF4XXt18+tXr6oImAOHwwFZ7CF0lljpUxiqgtlkhNhbIXAslGULOoHfAIZhg7laI8saZJEJ4+kGS3UM25hCm46w1saIaJOqbtW9C0x3DUyrBittmvolpTaQY+u6oVF/SJ0A+We9qbHbtanz4P9dit3Vwd5j9nghq9jvQQWpCEhe5g3CkF/X4u25wndT7hZU1QFpmpC6BMvlCpeXI1iWSfc7RFF0tOCktPk/sCxLUhUKbDAYYHDdx3A4pPslPM87qjxX+hq81z1wXVeUHKoKi+dn6UGG7cmLUPJnW97y9gQWIPvkeT7SJJW0FUXBeDymcUu+5nAcH0lSw/NpY69BFPPcdkZXqE5lr/VvD3sb4+n+AbPbr1B+XVM//sbD7QCP4yHW+v1LYNtWUdRAmULA/6Z+VJhTvySRB9dewd4YmM8mcLdrbE0DcehiT2vYEs5A03R86X+HbZuI4/jFkjMgP2APS/KrLPcELyhw95dXvCEDF4sFFe0a/f6VFG29XtNZ949Ke6wuCAIZEYGjKKT/vrTLeQUZGIaRPJ9Op5hMFOj6gj4shXTBscpcxS44SRJJgeGqqsp9mqZ0zjMBlmVBI8dC16BrKjR1jqauZD0X9XDYt0AO4Jlhtm3T7hNRwdXebDYUEIrPK+0ON98+4e7nFe5+XOLm+2d4qwks45mAGXGKk8IOyKoeHqjas5kA+Rl7xI1dZCnyXUQzrYt8ePRZCzwbaRzKplsn5+9hJUFcFA5kJYZhSB/O53PZqDP91MxAELLqSorYFjKTtup1i1gBg9kzy7LIcB2maco9d8F5vzmOg9FoJFa9epY/8p07X8dn/eLiQizpxHTv/wCnlQHnI4FGrQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"prototype 4\"\n        title=\"prototype 4\"\n        src=\"/static/7c71b35ad16d96a62ba9960d95d6d591/3d026/prototype_4.png\"\n        srcset=\"/static/7c71b35ad16d96a62ba9960d95d6d591/12f09/prototype_4.png 148w,\n/static/7c71b35ad16d96a62ba9960d95d6d591/e4a3f/prototype_4.png 295w,\n/static/7c71b35ad16d96a62ba9960d95d6d591/3d026/prototype_4.png 429w\"\n        sizes=\"(max-width: 429px) 100vw, 429px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<h4 id=\"1-먼저-위-코드에서-a-code-classlanguage-textchanwooprintnamecode을-수행하는-과정을-설명하겠습니다\" style=\"position:relative;\"><a href=\"#1-%EB%A8%BC%EC%A0%80-%EC%9C%84-%EC%BD%94%EB%93%9C%EC%97%90%EC%84%9C-a-code-classlanguage-textchanwooprintnamecode%EC%9D%84-%EC%88%98%ED%96%89%ED%95%98%EB%8A%94-%EA%B3%BC%EC%A0%95%EC%9D%84-%EC%84%A4%EB%AA%85%ED%95%98%EA%B2%A0%EC%8A%B5%EB%8B%88%EB%8B%A4\" aria-label=\"1 먼저 위 코드에서 a code classlanguage textchanwooprintnamecode을 수행하는 과정을 설명하겠습니다 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. 먼저 위 코드에서 A, <code class=\"language-text\">chanwoo.printName()</code>을 수행하는 과정을 설명하겠습니다.</h4>\n<ol>\n<li>인스턴스 <code class=\"language-text\">chanwoo</code>의 슬롯에 <code class=\"language-text\">printName()</code>이 존재하는지 확인합니다. 이 슬롯은 인스턴스 각각의 영역으로, <code class=\"language-text\">name</code> 프로퍼티만 존재합니다.<br>\n<br/></li>\n<li>\n<p><em>Prototype Link</em>를 통해 자신의 원형 객체인 <code class=\"language-text\">Human</code>의 <em>Prototype Object</em>에 접근합니다. </p>\n<ul>\n<li>모든 객체가 <em>Prototype Link</em>, <code class=\"language-text\">[[Prototype]]</code>프로퍼티를 가지기 때문에 생성자 함수 <code class=\"language-text\">Human</code>으로 생성되는 모든 인스턴스가 <code class=\"language-text\">Human</code>의 <em>Prototype Object</em>에 접근이 가능합니다.<br>\n<br/></li>\n</ul>\n</li>\n<li><code class=\"language-text\">Human</code>의 <em>Prototype Object</em> 내에 <code class=\"language-text\">printName()</code>이 존재하는지 확인합니다.<br>\n<br/></li>\n<li><code class=\"language-text\">printName()</code> 메소드가 존재하기 때문에 <em>Prototype Link</em>를 따라 더 조회하지 않고 해당 메소드를 수행합니다.<br>\n<br/></li>\n</ol>\n<h4 id=\"2-다음은-b-code-classlanguage-textchanwoohasownproperty39name39code을-수행하는-과정을-설명하겠습니다\" style=\"position:relative;\"><a href=\"#2-%EB%8B%A4%EC%9D%8C%EC%9D%80-b-code-classlanguage-textchanwoohasownproperty39name39code%EC%9D%84-%EC%88%98%ED%96%89%ED%95%98%EB%8A%94-%EA%B3%BC%EC%A0%95%EC%9D%84-%EC%84%A4%EB%AA%85%ED%95%98%EA%B2%A0%EC%8A%B5%EB%8B%88%EB%8B%A4\" aria-label=\"2 다음은 b code classlanguage textchanwoohasownproperty39name39code을 수행하는 과정을 설명하겠습니다 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. 다음은 B, <code class=\"language-text\">chanwoo.hasOwnProperty(&#39;name&#39;)</code>을 수행하는 과정을 설명하겠습니다.</h4>\n<ol start=\"3\">\n<li>1-3까지 위와 동일, <code class=\"language-text\">printName()</code> 대신, <code class=\"language-text\">hasOwnProperty()</code>로 바꿔서 이해하시면 되겠습니다.<br>\n<br/>  </li>\n<li>\n<p><code class=\"language-text\">Human</code>의 <em>Prototype Object</em> 내에 존재하지 않으므로 <em>Prototype Link</em>에 따라 모든 <em>Prototype Object</em>의 원형인 <code class=\"language-text\">Object</code>의 <em>Prototype Object</em>에 접근합니다. </p>\n<ul>\n<li><code class=\"language-text\">Object</code>의 <em>Prototype Object</em> 는 모든 <em>Prototype Object</em>가 <em>Prototype Link</em>로 참조하고 있기 때문에 모든 객체가 <code class=\"language-text\">Object</code>의 <code class=\"language-text\">Prototype Object</code>가 가진 프로퍼티와 메소드를 사용할 수 있습니다.<br>\n<br/>  </li>\n</ul>\n</li>\n<li><code class=\"language-text\">hasOwnProperty()</code> 메소드가 존재하기 때문에 <em>Prototype Link</em>를 따라 더 조회하지 않고 해당 메소드를 수행합니다.<br>\n<br/></li>\n</ol>\n<h4 id=\"3-마지막으로-c-code-classlanguage-textchanwooprintnicknamecode과-같이-prototype-chain-상에-존재하지-않는-메소드를-호출하는-경우입니다\" style=\"position:relative;\"><a href=\"#3-%EB%A7%88%EC%A7%80%EB%A7%89%EC%9C%BC%EB%A1%9C-c-code-classlanguage-textchanwooprintnicknamecode%EA%B3%BC-%EA%B0%99%EC%9D%B4-prototype-chain-%EC%83%81%EC%97%90-%EC%A1%B4%EC%9E%AC%ED%95%98%EC%A7%80-%EC%95%8A%EB%8A%94-%EB%A9%94%EC%86%8C%EB%93%9C%EB%A5%BC-%ED%98%B8%EC%B6%9C%ED%95%98%EB%8A%94-%EA%B2%BD%EC%9A%B0%EC%9E%85%EB%8B%88%EB%8B%A4\" aria-label=\"3 마지막으로 c code classlanguage textchanwooprintnicknamecode과 같이 prototype chain 상에 존재하지 않는 메소드를 호출하는 경우입니다 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3. 마지막으로 C, <code class=\"language-text\">chanwoo.printNickName()</code>과 같이 <em>Prototype Chain</em> 상에 존재하지 않는 메소드를 호출하는 경우입니다.</h4>\n<ol start=\"4\">\n<li>1-4까지 위 과정과 동일합니다.<br>\n<br/></li>\n<li><code class=\"language-text\">Object</code>의 <em>Prototype Object</em>에 존재하지 않아 <em>Prototype Link</em>를 따라 <em>Prototype Object</em>에 접근합니다. 이때, <em>Prototype Link</em>가  <code class=\"language-text\">null</code> 값을 가리키고 있습니다. <em>Prototype Chain</em>의 끝에 도달하였기 때문에 에러를 반환합니다.<br>\n<br/></li>\n</ol>\n<br/>\n<h2 id=\"prototype에서-주의할점\" style=\"position:relative;\"><a href=\"#prototype%EC%97%90%EC%84%9C-%EC%A3%BC%EC%9D%98%ED%95%A0%EC%A0%90\" aria-label=\"prototype에서 주의할점 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prototype에서 주의할점</h2>\n<hr>\n<ol>\n<li>\n<p><strong>생성자 함수를 통해 인스턴스를 선언한 이후에 <em>Prototype Object</em>가 가진 프로퍼티와 메소드가 변경되더라도 <em>Prototype Link</em>를 통해 가리키고 있는 모든 인스턴스에게 변경이 반영됩니다.</strong></p>\n<p>  생성자 함수를 통한 객체 생성과정을 설명하면서 인스턴스 생성 시점에 <em>Prototype Object</em>가 <em>Prototype Link</em>에 바인딩 된다고 설명하였습니다. 이때 중요한 것은 <strong>인스턴스 자신만의 <em>Prototype Object</em>가 생성되는 것이 아닌, <em>Prototype Link</em>를 통해  공통의 <em>Prototype Object</em>를 그저 참조만 하고 있다는 것입니다.</strong>  <em>Prototype Object</em> 내의 변화가 존재하더라도 참조하고 있는 포인터 <em>Prototype Link</em>는 그대로이기 때문에 그 변화가 인스턴스의 생성 시점과는 무관하게 반영될 수 있는 것입니다.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Human</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n    <span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">greet</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">hi, </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          \n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> chanwoo <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Human</span><span class=\"token punctuation\">(</span><span class=\"token string\">'chanwoo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> chanjong <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Human</span><span class=\"token punctuation\">(</span><span class=\"token string\">'chanjong'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nchanwoo<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                       <span class=\"token comment\">//  .... 1</span>\n\n<span class=\"token comment\">// 인스턴스 생성 이후에 Prototype Object의 메소드를 변경하였다.</span>\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">greet</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">안녕, </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          \n<span class=\"token punctuation\">}</span>\n\nchanwoo<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                       <span class=\"token comment\">//  .... 2</span>\nchanjong<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                      <span class=\"token comment\">//  .... 3</span></code></pre></div>\n<br/>\n<br/>\n</li>\n<li>\n<p><strong>동일한 이름의 프로퍼티와 메소드가 존재하더라도 <em>Prototype Chain</em>에서 우선적으로 조회되는 프로퍼티와 메소드를 사용합니다.</strong></p>\n<p>  주의할 것은 참조하기 위한 <strong><em>Prototype Chain</em></strong>의 순서입니다. <strong><em>Prototype Chain</em></strong>은 <code class=\"language-text\">Human</code> 인스턴스의 슬롯 <strong>→</strong> <code class=\"language-text\">Human</code> <em>Prototype Object</em> <strong>→</strong> <code class=\"language-text\">Object</code> <em>Prototype Object</em> <strong>→</strong> <code class=\"language-text\">null</code> 의 순으로 참조하면서 사용하고자 하는 프로퍼티, 메소드를 조회합니다. 동일한 프로퍼티, 메소드가 슬롯마다 정의될 수 있지만 <strong><em>Prototype Chain</em></strong>의 순서상 앞의 슬롯에 정의된 프로퍼티와 메소드가 우선으로 호출됩니다.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Human</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n\t<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">printName</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> by instance</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// ------ 1</span>\n\t<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// 생성자 함수의 prototype 프로퍼티를 통해서 메소드를 추가하였다.</span>\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">printName</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> by proto</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// ------ 2</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> chanwoo <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Human</span><span class=\"token punctuation\">(</span><span class=\"token string\">'chanwoo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nchanwoo<span class=\"token punctuation\">.</span><span class=\"token function\">printName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                <span class=\"token comment\">// ----- A</span></code></pre></div>\n<br/>\n<p>  예시는 위의 예시에서 동일한 이름을 가진 <code class=\"language-text\">printName()</code> 메소드가 인스턴스에도 선언되어있는 것을 볼 수 있습니다. 즉, 위 그림에서 살색의 1번 영역과 3번 영역 모두 동일한 이름의 <code class=\"language-text\">printName()</code> 메소드가 선언된 상태입니다. 하지만 <em>Prototype Chain</em>의 순서상, 인스턴스의 슬롯인 1번을 먼저 조회하기 때문에 결과는 1번 줄이 수행됩니다. 이는 클래스의 메소드 오버라이딩의 개념과 동일하게 동작합니다.</p>\n</li>\n</ol>\n<br/>\n<ol start=\"3\">\n<li>\n<p><strong>객체 생성 방식에 따라 Prototype Link에 바인딩되는 Prototype Object가 다릅니다.</strong></p>\n<ol>\n<li><strong>생성자 함수와 <code class=\"language-text\">new</code> 연산자</strong><br>\n생성되는 객체의 <em>Prototype Link</em>는 생성자 함수의 <em>Prototype Object</em>가 바인딩됩니다.<br>\n<br/></li>\n<li><strong><code class=\"language-text\">{}</code></strong> <strong>object initializer notation</strong><br>\n생성되는 객체의 <em>Prototype Link</em>는 최상위 Prototype Object인 <code class=\"language-text\">Object</code> <em>Prototype Object</em>가 바인딩 됩니다.<br>\n<br/></li>\n<li><strong><code class=\"language-text\">Object.create(&lt;proto&gt;)</code></strong><br>\n생성되는 객체의 <em>Prototype Link</em>는 인자로 전달되는 <code class=\"language-text\">*proto*</code>에 바인딩됩니다.</li>\n</ol>\n</li>\n</ol>\n<br/>\n<h2 id=\"그래서-prototype-chain을-말하자면\" style=\"position:relative;\"><a href=\"#%EA%B7%B8%EB%9E%98%EC%84%9C-prototype-chain%EC%9D%84-%EB%A7%90%ED%95%98%EC%9E%90%EB%A9%B4\" aria-label=\"그래서 prototype chain을 말하자면 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>그래서 Prototype Chain을 말하자면..</h2>\n<hr>\n<p>  <em>Prototype Object</em>와 <em>Prototype Link</em>를 통해 <strong>프로퍼티와 메소드의 상속 방식</strong>을 정의하였다면, <em>Prototype Chain</em>은 <strong>상속된 프로퍼티와 메소드를 사용하는 방식</strong>이라고 볼 수 있습니다. 프로퍼티나 메소드가 자신의 슬롯에 존재하지 않는 경우, <em>Prototype Link</em>를 통해 자신의 원형 객체 <em>Prototype Object</em>에 접근하여 조회하는 방식이 선형적으로 수행되기 때문에 <strong><em>Prototype Chain</em></strong>이라고 부르게 되었습니다.</p>\n<br/>\n<h2 id=\"끝으로\" style=\"position:relative;\"><a href=\"#%EB%81%9D%EC%9C%BC%EB%A1%9C\" aria-label=\"끝으로 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>끝으로</h2>\n<hr>\n<p>  JS의 객체에 대해 깊이 있게 다뤄보았습니다. 객체의 생성과정, 원형 객체 <em>Prototype Object</em>, 원형 객체 포인터 <em>Prototype Link</em>, 그리고 이 둘을 통해 상속받는 메소드와 프로퍼티를 조회하는 방식 <em>Prototype Chain</em>에 관해 설명하였습니다. 다음 포스팅은 객체 생성과정에서 나왔던 <code class=\"language-text\">this</code>에 관해 설명해보도록 하겠습니다.</p>","excerpt":"프로토 타입이란? Prototype이란, '원형' 의 뜻을 가지며, 시스템의 미완성 버전 또는 중요한 가능들이 포함된 시스템의 초기모델을 의미한다.   JS에서는 모든 것이 객체입니다. 우리가 사용하는 배열이나 함수도 하나의 객체인데요. 우리가 정의…","tableOfContents":"<ul>\n<li>\n<p><a href=\"/prototype/#%ED%94%84%EB%A1%9C%ED%86%A0-%ED%83%80%EC%9E%85%EC%9D%B4%EB%9E%80\">프로토 타입이란?</a></p>\n<ul>\n<li>\n<ul>\n<li><a href=\"/prototype/#%EC%83%9D%EC%84%B1%EC%9E%90-%ED%95%A8%EC%88%98%EC%99%80-code-classlanguage-textnewcode-%EC%97%B0%EC%82%B0%EC%9E%90%EB%A5%BC-%ED%86%B5%ED%95%9C-%EA%B0%9D%EC%B2%B4-%EC%83%9D%EC%84%B1%EA%B3%BC%EC%A0%95\">생성자 함수와 <code class=\"language-text\">new</code> 연산자를 통한 객체 생성과정</a></li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><a href=\"/prototype/#%ED%94%84%EB%A1%9C%ED%86%A0%ED%83%80%EC%9E%85%EC%9D%98-%EA%B5%AC%EC%A1%B0\">프로토타입의 구조</a></p>\n<ul>\n<li><a href=\"/prototype/#prototype-object\">Prototype Object</a></li>\n<li><a href=\"/prototype/#prototype-link\">Prototype Link</a></li>\n<li><a href=\"/prototype/#%EA%B7%B8%EB%9E%98%EC%84%9C-prototype-object-prototype-link%EB%A5%BC-%EB%A7%90%ED%95%98%EC%9E%90%EB%A9%B4\">그래서 Prototype Object, Prototype Link를 말하자면..</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"/prototype/#prototype-chain\">Prototype Chain</a></p>\n<ul>\n<li><a href=\"/prototype/#prototype%EC%97%90%EC%84%9C-%EC%A3%BC%EC%9D%98%ED%95%A0%EC%A0%90\">Prototype에서 주의할점</a></li>\n<li><a href=\"/prototype/#%EA%B7%B8%EB%9E%98%EC%84%9C-prototype-chain%EC%9D%84-%EB%A7%90%ED%95%98%EC%9E%90%EB%A9%B4\">그래서 Prototype Chain을 말하자면..</a></li>\n<li><a href=\"/prototype/#%EB%81%9D%EC%9C%BC%EB%A1%9C\">끝으로</a></li>\n</ul>\n</li>\n</ul>","fields":{"slug":"/prototype/"},"frontmatter":{"title":"JS의 기본 개념 1. 프로토타입","date":"Nov 05, 2021","tags":["JS","Vanila","Front-End"],"keywords":["무지성 개발 탈출기","Chanuuuu"],"update":"Jan 01, 0001"}}},"pageContext":{"slug":"/prototype/","series":[],"lastmod":"2021-11-05"}},"staticQueryHashes":["2027115977","694178885"]}